package com.online.web.signature;

import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

public class WeatherApiClient {
    private static final String BASE_URL = "http://t.weather.sojson.com/api/weather/city/";

    public String getWeatherInfo(String cityId) {
        RestTemplate restTemplate = new RestTemplate();

        // 构建完整的URL
        String url = BASE_URL + cityId;

        // 发送GET请求并获取响应结果
        ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.GET, null, String.class);
        String response = responseEntity.getBody();

        return response;
    }

    public static void main(String[] args) {
        WeatherApiClient client = new WeatherApiClient();
        String cityId = "101010100"; // 假设城市ID为北京
        String weatherInfo = client.getWeatherInfo(cityId);
        System.out.println(weatherInfo);
    }
}
